package 代码记录.校招笔试真题.笔试真题_2022.欧克云链;

/**
 * @author zx
 * @create 2022-10-22 15:10
 */
public class 计算数值的整数次方 {
    /**
     * @return 100%
     */
    public double myPow (double x, int n) {
        double res = 1.0;
        if(n >= 0){
            while(n > 0){
                res = res * x;
                n--;
            }
        }else{
            n = -n;
            while(n > 0){
                res = res * x;
                n--;
            }
            res = 1 / res;
        }
        return res;
    }
}
